#include <REGX52.H>
#include <INTRINS.h>
#include "Timer.h"
#include "LCD1602.h"


int sec = 57;
int min = 58;
int hour = 1;
void main()
{
	TimerInit();
	LCD_Init();
	LCD_ShowString(1,1,"CLOCK");
	LCD_ShowString(2,1,"  :  :");	
	while(1)
	{
		// 00:00:00
		LCD_ShowNum(2,7,sec,2);
		LCD_ShowNum(2,4,min,2);
		LCD_ShowNum(2,1,hour,2);
	}
}


// 中断函数的入口
void Timer0_Routine(void)		interrupt 1
{
	static int countT = 0; 
	TL0 = 0x18;		
	TH0 = 0xFC;	
	countT++;
	if(countT >= 1000)
	{
		countT = 0;
		sec++;
		if(sec == 60)
		{
			min++;
			sec = 0;
		}
		if(min == 60)
		{
			hour++;
			min = 0;
		}
		if(hour == 24)
		{
			sec = min = hour = 0;
		}
	}	
}